﻿<UserControl 
    x:Class="CCCBrowser.QuickPlanControl"
    xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
     xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   xmlns:theming="clr-namespace:System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.Toolkit"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
   xmlns:ui="clr-namespace:CCCBrowser"
   xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
   xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Loaded="UserControl_Loaded"
    
    >
    <Grid x:Name="LayoutRoot"
    
    >
    
   
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />  <!-- Heading -->
            <RowDefinition Height="Auto" />  <!-- Tab Control -->
        </Grid.RowDefinitions>
        
        <basics:TabControl Grid.Row="1" 
        >
            <basics:TabItem x:Name="tbiDiagnoses" Header="Diagnoses" >
                <!--<basics:TabItem.Header>
                    <StackPanel  Background="{StaticResource DiagnosisBackground}" >
                        <TextBlock  Text="Diagnoses" Margin="3" FontWeight="Bold" FontSize="14"   />
                    </StackPanel>

                </basics:TabItem.Header>-->

                <StackPanel>

                    
                    <data:DataGrid x:Name="dgDiagnoses" 
                                       AutoGenerateColumns="False" 
                       CanUserSortColumns="True"
                       SelectionMode="Single"
                      
                        MaxHeight="250"
                        >
                    <data:DataGrid.Columns>

                        <data:DataGridTemplateColumn  Width="25" >
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button  Margin="2" x:Name="btnDelete" Click="btnDelete_Click" Height="30" 
                            HorizontalAlignment="Center" >
                                        <Button.Content>
                                            <Image Source="Icons/Delete.png" />
                                        </Button.Content>
                                    </Button>

                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>

                        <data:DataGridTextColumn Header="Date"
                Binding="{Binding Date}" Width="150"  />


                        <data:DataGridTextColumn Header="Component"  CanUserSort="True"
                Binding="{Binding Tag.ComponentName}" Width="150"  />

                        <!--<data:DataGridTextColumn Header="Date" 
                Binding="{Binding Date}" Width="150"  />
                <data:DataGridTextColumn Header="Description" 
                Binding="{Binding Description}" Width="300"  />
                <data:DataGridTextColumn Header="Tag" 
                Binding="{Binding Tag.Concept}" Width="150"  />-->
                        <data:DataGridTemplateColumn Header="Diagnosis" Width="350" x:Name="columnDiagnosis" >
                            <data:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                                <RowDefinition />
                                                <RowDefinition />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                        <!--<TextBlock Grid.Row="0" FontSize="8" HorizontalAlignment="Right" Text="{Binding Date}" />-->
                                           <TextBlock Grid.Row="2" Text="{Binding Tag.Concept}" ToolTipService.ToolTip="{Binding Tag.Definition}" FontWeight="Bold" />
                                            <TextBlock Grid.Row="0" Text="{Binding Title}" FontWeight="Bold" />
                                            <TextBlock Grid.Row="1" Text="{Binding Description }" TextWrapping="Wrap" Margin="4,2,4,2" FontStyle="Italic"/>
                                        <!--<TextBlock Grid.Row="2" Text="{Binding Tag.ComponentName}" TextWrapping="Wrap" Margin="4,2,4,2" FontStyle="Italic"/>-->

                                    </Grid>
                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellTemplate>

                            <data:DataGridTemplateColumn.CellEditingTemplate>

                                <DataTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <!--<TextBlock Grid.Row="0" FontSize="8" HorizontalAlignment="Right" Text="{Binding Date}" />-->
                                            <TextBox Grid.Row="0" Text="{Binding Title,Mode=TwoWay}"  FontWeight="Bold" />
                                            <TextBox Grid.Row="1" Text="{Binding Tag.Concept,Mode=OneTime}" ToolTipService.ToolTip="{Binding Tag.Definition}" FontWeight="Bold" />
                                        <TextBox Grid.Row="2" 
                                     Text="{Binding Description,Mode=TwoWay}" 
                                     Margin="4,2,4,2" FontStyle="Italic" TextWrapping="Wrap"/>
                                    </Grid>

                                </DataTemplate>
                            </data:DataGridTemplateColumn.CellEditingTemplate>
                        </data:DataGridTemplateColumn>

                        <data:DataGridTextColumn Header="Outcome"  CanUserSort="True"
                Binding="{Binding Tag.Outcome.Concept}" Width="70"  />

                    </data:DataGrid.Columns>
                </data:DataGrid>
                
                </StackPanel>
            </basics:TabItem>
            
            <basics:TabItem x:Name="tbiInterventions"  Header="Interventions">
                <!--<basics:TabItem.Header>
                    <StackPanel Background="{StaticResource InterventionBackground}">
                        <TextBlock  Text="Interventions" Margin="3"  FontWeight="Bold" FontSize="14"   />

                    </StackPanel>

                </basics:TabItem.Header>-->

                <StackPanel>
                
                    
        <data:DataGrid x:Name="dgInterventions" CanUserSortColumns="True" 
        AutoGenerateColumns="False" SelectionMode="Single"
        MaxHeight="250"
   
        >
                        <data:DataGrid.Columns>
                            <data:DataGridTemplateColumn  Width="25"  >
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button  Margin="2" x:Name="btnDelete" Click="btnDeleteInterv_Click" Height="30" 
                            HorizontalAlignment="Center">
                                            <Button.Content>
                                                <Image Source="Icons/Delete.png" />
                                            </Button.Content>
                                        </Button>

                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>
                            </data:DataGridTemplateColumn>

                            <data:DataGridTextColumn Header="Date"
                Binding="{Binding Date}" Width="150"  />


                            <data:DataGridTemplateColumn Header="Time">

                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Task.Hours,Mode=TwoWay}" />
                                            <TextBlock Text=":" />
                                            <TextBlock Text="{Binding Task.Minutes,Mode=TwoWay}" />
                                        </StackPanel>

                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>

                                <data:DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <ui:TimeControl Hours="{Binding Path=Task.Hours,Mode=TwoWay}"
                                     Minutes="{Binding Path=Task.Minutes,Mode=TwoWay}" />
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellEditingTemplate>

                            </data:DataGridTemplateColumn>


                            <data:DataGridTextColumn Header="Component"  CanUserSort="True"
                Binding="{Binding Tag.ComponentName}" Width="150"  />

                            <!--<data:DataGridTextColumn Header="Date" 
                Binding="{Binding Date}" Width="150"  />
                <data:DataGridTextColumn Header="Description" 
                Binding="{Binding Description}" Width="300"  />
                <data:DataGridTextColumn Header="Tag" 
                Binding="{Binding Tag.Concept}" Width="150"  />-->

                            <data:DataGridTextColumn Header="Type"  CanUserSort="True"
                Binding="{Binding Tag.ActionType.Concept}" Width="70"  />

                            <data:DataGridTemplateColumn Header="Intervention" Width="350" x:Name="columnIntervention"  >
                                <data:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <!--<TextBlock Grid.Row="0" FontSize="8" HorizontalAlignment="Right" Text="{Binding Date}" />-->
                                            <TextBlock Grid.Row="0" Text="{Binding Tag.Concept}" ToolTipService.ToolTip="{Binding Tag.Definition}" FontWeight="Bold" />
                                            <TextBlock Grid.Row="1" Text="{Binding Description }" TextWrapping="Wrap" Margin="4,2,4,2" FontStyle="Italic"/>
                                            <!--<TextBlock Grid.Row="2" Text="{Binding Tag.ComponentName}" TextWrapping="Wrap" Margin="4,2,4,2" FontStyle="Italic"/>-->

                                        </Grid>
                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellTemplate>

                                <data:DataGridTemplateColumn.CellEditingTemplate>

                                    <DataTemplate>
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <!--<TextBlock Grid.Row="0" FontSize="8" HorizontalAlignment="Right" Text="{Binding Date}" />-->
                                            <TextBox Grid.Row="0" Text="{Binding Tag.Concept,Mode=TwoWay}" ToolTipService.ToolTip="{Binding Tag.Definition}" FontWeight="Bold" />
                                            <TextBox Grid.Row="1" 
                                     Text="{Binding Description,Mode=TwoWay}" 
                                     Margin="4,2,4,2" FontStyle="Italic" TextWrapping="Wrap"/>
                                        </Grid>

                                    </DataTemplate>
                                </data:DataGridTemplateColumn.CellEditingTemplate>
                            </data:DataGridTemplateColumn>



                        </data:DataGrid.Columns>
                    </data:DataGrid>

                </StackPanel>
                
            </basics:TabItem>
            
            <basics:TabItem Header="Statistics">

                <StackPanel>

                    <charting:Chart
                    x:Name="chartDiagnosisComponents" 
                    Title="Diagnoses vs. Components"
                    >
                        <charting:Chart.Series>
                            <charting:PieSeries
                             
                            ItemsSource="{Binding}"
                            DependentValueBinding="{Binding Value}"
                            IndependentValueBinding="{Binding Key}"
                            />
                        </charting:Chart.Series>
                    </charting:Chart>


                    <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <charting:Chart Grid.Column="0" 
                        HorizontalAlignment="Left"
                    x:Name="chartInterventionComponents" 
                    Title="Interventions vs. Components"
                    Margin="1"
                    >

                                <charting:Chart.Series>
                                    <charting:BarSeries Title="Interventions" 
                            ItemsSource="{Binding}"
                            DependentValueBinding="{Binding Value}" 
                            IndependentValueBinding="{Binding Key}"
                            />
                                </charting:Chart.Series>

                            </charting:Chart>


                            <charting:Chart Grid.Column="1" HorizontalAlignment="Right"
                    x:Name="chartTaskTimeVsComponents" 
                    Title="Task time vs. Components"
                    Margin="1"
                    >

                                <charting:Chart.Series>
                                    <charting:PieSeries 
                            ItemsSource="{Binding}"
                            DependentValueBinding="{Binding Value.Minutes}"
                            IndependentValueBinding="{Binding Key}"
                            />
                                </charting:Chart.Series>

                            </charting:Chart>
                        </Grid>
                   

                </StackPanel>

            </basics:TabItem>
        </basics:TabControl>


        <StackPanel Grid.Row="0" Background="DarkGray" Orientation="Horizontal">

            <Button x:Name="btnSave" Grid.Row="0" Width="30"  Click="btnSave_Click" HorizontalAlignment="Left"
         Margin="2" ToolTipService.ToolTip="Saves template"
         >
                <Button.Content>
                    <Image Source="Icons/Save.png" Height="20" />
                </Button.Content>
                <!--<TextBlock Grid.Row="1" Text="Quick plan" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>-->
            </Button>

            <Button x:Name="btnDiagnosis"  Width="30"  Click="btnDiagnosis_Click" HorizontalAlignment="Left"
         Margin="2" ToolTipService.ToolTip="Creates new diagnosis"
         >
                <Button.Content>
                    <Image Source="Icons/Save.png" Height="20" />
                </Button.Content>
                <!--<TextBlock Grid.Row="1" Text="Quick plan" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>-->
            </Button>

            <Button x:Name="btnIntervention"  Width="30"  Click="btnIntervention_Click" HorizontalAlignment="Left"
         Margin="2" ToolTipService.ToolTip="Creates new intervention"
         >
                <Button.Content>
                    <Image Source="Icons/Save.png" Height="20" />
                </Button.Content>
                <!--<TextBlock Grid.Row="1" Text="Quick plan" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>-->
            </Button>


        </StackPanel>
        <!-- Resource : http://www.silverlightshow.net/items/Using-the-GridSplitter-control-in-Silverlight-2-Beta-1.aspx-->
        <!--<basics:GridSplitter Grid.Row="3" Height="1" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Center" Background="Black" />-->

    </Grid>
</UserControl>
